/**
 * WizardStep Class
 */
syslib.ui.WizardStep = {};
syslib.ui.WizardStep.Conversor = syslib.object.createClass();
syslib.ui.WizardStep.Conversor.extend(syslib.ui.VisualTag);
syslib.ui.WizardStep.Conversor.extend({
	__parentTagName : "wizardpanel",

	prepare : function(){
		// TAG ATTRIBUTES
		var attributes = this.__attributes;
		if(!__valid(attributes.name)){
			syslib.messages.error("You can't insert an unamed step on a wizard panel!");
			return false;
		}

		// CLASS ATTRIBUTES
		this.addProperty("string", "id", "");
		this.addProperty("string", "name", "");
		this.addProperty("string", "title", "");
		this.addProperty("string", "page", "");

		this.addProperty("string", "next", "");
		this.addProperty("string", "previous", "");

		this.addProperty("boolean", "nextEnabled", true);
		this.addProperty("boolean", "previousEnabled", true);
		this.addProperty("boolean", "cancelEnabled", true);
		this.addProperty("boolean", "finishEnabled", false);

		this.addProperty("boolean", "validateForm", false);

		this.addProperty("boolean", "ajax", false);
		this.addProperty("boolean", "postData", false);

		this.addProperty("object", "wizard", {});

		// SETS
		(!__valid(attributes.next)) ? this.setNextEnabled(false) : this.setNext(attributes.next);
		(!__valid(attributes.previous)) ? this.setPreviousEnabled(false) : this.setPrevious(attributes.previous);

		if(__valid(attributes.finish) && attributes.finish != "false")
			this.setFinishEnabled(true);

		if(__valid(attributes.cancel) && attributes.cancel == "false")
			this.setCancelEnabled(false);

		if(__valid(attributes.page) && attributes.page !== "false"){
			this.setPage(attributes.page);
			this.setAjax(true);
		}

		if(__valid(attributes.title))
			this.setTitle(attributes.title);

		if(__valid(attributes.postdata) && attributes.postdata !== "false")
			this.setPostData(true);

		if(__valid(attributes.validateform) && attributes.validateform !== "false")
			this.setValidateForm(true);

		this.setId( (__valid(attributes.id)) ? attributes.id : "wizardstep" + Math.floor(Math.random() * 1001) );
		this.setName(attributes.name);
		this.setWizard( this.__parent );
		
		// RETURN
		return true;
	},

	execute : function(){
		// JSON
		var elemtJSON = ["div", {"class" : "wizard-step-body"}];

		// OBJECT
		var step = this.createDOM(elemtJSON);

		// UPDATE AND RETURN
		step.innerHTML = this.__innerHTML;
		return step;
	},

	finalize : function(){
		// GETS THE WIZARD
		var wizard = this.getWizard();

		// ADD ITSELF AS A STEP
		wizard.addStep(this);
		if(__valid( this.__attributes.selected )){
			// SELECT
			wizard.selectStep(this.getName());
		}
	},

	onEvent : function(eventName){
		var eventName 	= "on" + eventName;
		var attribs		= this.__attributes;

		if(__valid(attribs[eventName])){
			return eval(attribs[eventName]);
		} else {
			return true;
		}
	}
});